package com.gitee.wsl.mathematics.geometry.d2.rect.ext

import com.gitee.wsl.mathematics.coordinate.d2.Coordinate2
import com.gitee.wsl.mathematics.geometry.d2.rect.RectangleShape2d
import com.gitee.wsl.mathematics.vector.vec2.Vector2

/** Moves this rectangle so that its center point is located at a given position (x, y) */
fun<N:Number,V: Coordinate2<N, V>,R: RectangleShape2d<N, V, R>> RectangleShape2d<N, V, R>.setCenter(x: N, y: N) = setPosition(x - width * 0.5f, y - height * 0.5f)

/** Moves this rectangle so that its center point is located at a given position
 * @param position the position
 * @return this for chaining
 */
fun<N:Number,V: Coordinate2<N, V>,R:RectangleShape2d<N, V,R>> RectangleShape2d<N, V,R>.setCenter(position: Vector2<N,*>) = setPosition(position.x - width / 2, position.y - height / 2)
